// src/user/user.module.ts
import { Module } from '@nestjs/common';
import { MongooseModule, getConnectionToken } from '@nestjs/mongoose';
import { Connection } from 'mongoose';
import * as AutoIncrementFactory from 'mongoose-sequence';
import { User, UserSchema } from './schemas/user.schema';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { CustomLoggerProvider } from '../common/provider/logger.provider';
import { ValidationService } from '../common/services/validation.service';

@Module({
  imports: [
    MongooseModule.forFeatureAsync([
      {
        name: User.name,
        useFactory: (connection: Connection) => {
          const AutoIncrement = AutoIncrementFactory(connection);
          UserSchema.plugin(AutoIncrement, {
            inc_field: 'id',
            id: 'users_id_counter',
          });
          return UserSchema;
        },
        inject: [getConnectionToken()],
      },
    ]),
  ],
  providers: [UserService, CustomLoggerProvider, ValidationService],
  controllers: [UserController],
})
export class UserModule {}
